from keras.datasets import mnist
import matplotlib.pyplot as plt

# 导入mnist数据集
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

# 查看任意图片的热点图以及十六进制表示
t = int(input("请输入要查看的数据集图片: "))
image = train_images[t]
plt.imshow(train_images[t], cmap=plt.get_cmap('gray'))
plt.show()
plt.close()

print("查看的图片标签为", train_labels[t])
w, h = image.shape
for i in range(w):
    for j in range(h):
        print("{0:0>2}".format(hex(image[i][j])[2:]), end=' ')
    print()